package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.company.ComCompanyDTO;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.SelectVo;
import com.bf.electroplating.pojo.vo.company.ComCompanyVO;
import com.bf.electroplating.service.ComCompanyService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/company")
@Tag(name = "企业档案", description = "企业档案")
public class ComCompanyController {

    @Autowired
    private ComCompanyService comCompanyService;

    @PostMapping("/list")
    @Operation(summary = "获取企业列表", description = "分页获取企业列表信息")
    public ResultVO<Page<ComCompanyVO>> getCompanyList(@RequestBody ComCompanyDTO dto) {
        return ResultVO.ok(comCompanyService.getCompanyList(dto));
    }

    @PostMapping("/getCompanyById")
    @Operation(summary = "获取企业详情", description = "根据ID获取企业详细信息")
    public ResultVO<ComCompanyVO> getCompanyById(@RequestBody IdDTO id) {
        return ResultVO.ok(comCompanyService.getCompanyById(id.getId()));
    }

    @GetMapping("/select")
    @Operation(summary = "获取企业下拉框", description = "获取企业ID和名称的下拉框数据")
    public ResultVO<List<SelectVo>> getCompanySelect() {
        return ResultVO.ok(comCompanyService.getCompanySelect());
    }

    @GetMapping("/selectInfo")
    @Operation(summary = "获取企业下拉框", description = "获取企业ID和名称的下拉框数据")
    public ResultVO<List<SelectVo>> getCompanySelectInfo() {
        return ResultVO.ok(comCompanyService.getCompanySelect());
    }

    @GetMapping("/selectInfoWithOutPlant")
    @Operation(summary = "获取企业下拉框-无污水厂", description = "获取企业ID和名称的下拉框数据-无污水厂")
    public ResultVO<List<SelectVo>> selectInfoWithOutPlant() {
        return ResultVO.ok(comCompanyService.selectInfoWithOutPlant());
    }


    @GetMapping("/selectWaterPlantInfo")
    @Operation(summary = "获取污水厂下拉框", description = "获取企业ID和名称的污水厂下拉框数据")
    public ResultVO<List<SelectVo>> selectWaterPlantInfo() {
        return ResultVO.ok(comCompanyService.selectWaterPlantInfo());
    }


    @Idempotent
    @PostMapping("/saveCompany")
    @Operation(summary = "新增企业", description = "新增企业信息")
    public ResultVO<Boolean> saveCompany(@RequestBody ComCompanyVO vo) {
        return ResultVO.ok(comCompanyService.saveCompany(vo), "保存成功");
    }
    @Idempotent
    @PostMapping("/updateCompany")
    @Operation(summary = "修改企业", description = "修改企业信息")
    public ResultVO<Boolean> updateCompany(@RequestBody ComCompanyVO vo) {
        return ResultVO.ok(comCompanyService.updateCompany(vo), "保存成功");
    }

    @PostMapping("/deleteCompany")
    @Operation(summary = "删除企业", description = "根据ID删除企业信息")
    public ResultVO<Boolean> deleteCompany(@RequestBody IdDTO id) {
        return ResultVO.ok(comCompanyService.deleteCompany(id.getId()), "删除成功");
    }

    @PostMapping("/batch")
    @Operation(summary = "批量删除企业", description = "批量删除企业信息")
    public ResultVO<Boolean> batchDeleteCompany(@RequestBody List<String> ids) {
        return ResultVO.ok(comCompanyService.batchDeleteCompany(ids), "删除成功");
    }
} 